package com.wpre.springioc.bean;

import com.wpre.springioc.model.UserInfo;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-10-26
 * Time: 15:37
 */
@Component
public class UserBean {

    //创建多个对象(3个,可以根据名称拿到该对象),把这些对象交给Spring管理,可以使用@Bean
    //@Bean:方法注解,需要配合@Component、Configuration、Controller、Service、Repository其中任意一个使用
    @Bean("zhangsan")
    @Primary
    public UserInfo UserInfo1() {

        return new UserInfo("张三", 18);
    }

    @Bean("lisi")
    public UserInfo UserInfo2() {

        return new UserInfo("李四", 18);
    }

    @Bean("wangwu")
    public UserInfo UserInfo3() {

        return new UserInfo("王五", 18);
    }

    //Spring也可以管理Java内置的对象
    @Bean
    public String name() {
        return "testName";
    }

    @Bean()
    public UserInfo UserInfo4(String name) {

        return new UserInfo(name, 18);
    }

    @Bean()
    public UserInfo UserInfo5(@Qualifier("name") String name1) {

        return new UserInfo(name1, 18);
    }

}
